<template>
    <div>
        <h1>病房信息显示</h1>
        <hr>
        
        <a href="/BingAdd">病房信息新增</a>
        <hr>
        <a href="/DepShow">科室信息显示</a>
        <hr>
        病房名称
        <input type="text" v-model="cha.BingName">
        <input type="button" value="查询" @click="Show">
        <table class="table">
            <thead>
                <tr>
                    <td>病房编号</td>
                    <td>病房名称</td>
                    <td>房间号</td>
                    <td>所属科室</td>
                    <td>床位总数量</td>
                    <td>床位状态</td>
                    <td>空闲床数量</td>
                    <td>创建日期</td>
                    <td>病房状态</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in data">
                    <td>{{a.BingId}}</td>
                    <td>{{a.BingName}}</td>
                    <td>{{a.BingNum}}</td>
                    <td>{{a.DepName}}</td>
                    <td>{{a.BingSum}}</td>
                    <td>{{a.BingBedState?"已满":"未满"}}</td>
                    <td>{{a.BingBedNum}}</td>
                    <td>{{moment(a.BingDate).format("YYYY年MM月DD日")}}</td>
                    <td>{{a.BingState?"启用":"维修"}}</td>
                    <td>
                        <input type="button" value="修改状态" @click="UpdStat(a.BingId)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import { ref,onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
onMounted(()=>{
    Show();
})
const data = ref([{
    "BingId": 1,
    "BingName": "抢救室",
    "BingNum": 101,
    "BingSum": 2,
    "BingBedState": false,
    "BingBedNum": 1,
    "BingDate": "2025-05-19T03:19:16.668",
    "BingState": true,
    "DepId": 1,
    "DepName": "脑科"
}])
const cha=ref({
    "BingName": ""
})
const Show =()=>{
    axios.get('https://localhost:7087/api/Bing/BingShow',{params:cha.value}).then(res=>{
        data.value = res.data;
    })
}
//修改状态
const UpdStat = (e:any)=>{
    if(confirm("确定修改吗？")){
        axios.get('https://localhost:7087/api/Bing/UpdState',{params:{BingId:e}}).then(res=>{
            if(res.data>0){
                alert('修改成功')
                Show()
            }
            else{
                alert('修改失败');
            }
        })
    }
}


</script>

<style scoped>

</style>